package com.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.entity.User;
import com.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zgg
 * @since 2021-08-24
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService ius;
    @GetMapping("/{name}/{pwd}")
    public User login(@PathVariable("name") String name,
                      @PathVariable("pwd") String pwd, HttpSession session){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",name).eq("password",pwd);
        User user = ius.getOne(wrapper);
        if(user != null){
            session.setAttribute("user",user);
        }
        return user;
    }
    @PostMapping("/logout")
    public void logout(HttpSession session){
        session.invalidate();
    }

}

